﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using Quartz;
using Quartz.Impl;



namespace House_Control
{
    //This class will deal with secheduling all of the appliances in the house.
    public class Schedule
    {
        //static long startTime;
        DateTime x;
        Appliance app;
        

        public Schedule(int month, int day, int year, int hour, int min)
        {
           // construct a scheduler factory
            ISchedulerFactory schedFact = new StdSchedulerFactory();
            // get a scheduler
            IScheduler sched = schedFact.GetScheduler();
            sched.Start();
            // define the job and tie it to our HelloJob class
            IJobDetail job = JobBuilder.Create<startJob>()
                .WithIdentity("job1", "group1")
                .Build();

            x = new DateTime(year,month,day,hour,min,0);

            ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
                                                          .WithIdentity("trigger1", "group1")
                                                          .StartAt(x)
                                                          .Build();
            //schedule it to run
            DateTimeOffset? ft = sched.ScheduleJob(job, trigger);

        }
        public Schedule(Appliance app,int month, int day, int year, int hour, int min)
        {
            // construct a scheduler factory
            ISchedulerFactory schedFact = new StdSchedulerFactory();
            // get a scheduler
            IScheduler sched = schedFact.GetScheduler();
            sched.Start();
            // define the job and tie it to our HelloJob class
            IJobDetail job = JobBuilder.Create<specJob>()
                .WithIdentity("job2", "group2")
                .Build();


            this.app = app;
            x = new DateTime(year, month, day, hour, min, 0);

            ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
                                                          .WithIdentity("trigger2", "group2")
                                                          .StartAt(x)
                                                          .Build();
            //schedule it to run
            DateTimeOffset? ft = sched.ScheduleJob(job, trigger);
        }

        public Appliance getAppliance()
        {
            return app;
            }


    }
}
